﻿using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class RankPanel : MonoBehaviour
{
    private Button bg_btn;

    public Text[] txt_Scores;

    private GameObject go_RankList;

    private void Awake()
    {
        EventCenter.AddListener(EventDefine.ShowRankPanel,Show);
        bg_btn = transform.Find("bg_btn").GetComponent<Button>();
        bg_btn.onClick.AddListener(OnImageButtonClose);
        go_RankList = transform.Find("RankList").gameObject;

        //隐藏
        bg_btn.GetComponent<Image>().color = new Color(
            bg_btn.GetComponent<Image>().color.r,
            bg_btn.GetComponent<Image>().color.g, 
            bg_btn.GetComponent<Image>().color.b,0);

        go_RankList.transform.localScale = Vector3.zero;
        gameObject.SetActive(false);
    }
    public void Show()
    {
        gameObject.SetActive(true);
        //显示
        bg_btn.GetComponent<Image>().DOColor(new Color(
            bg_btn.GetComponent<Image>().color.r,
            bg_btn.GetComponent<Image>().color.g,
            bg_btn.GetComponent<Image>().color.b,0.3f),0.3f);
        //旋转
        go_RankList.transform.DOScale(Vector3.one,0.3f);

        //成绩的显示
        int[] arr = GameManager.Instance.GetBestArr();
        for (int i = 0; i < arr.Length; i++)
        {
            txt_Scores[i].text = arr[i].ToString();
        }
    }
    private void OnDestroy()
    {
       EventCenter.RemoveListener(EventDefine.ShowRankPanel, Show);
    }
    private void OnImageButtonClose()
    {
        //隐藏
        bg_btn.GetComponent<Image>().DOColor(new Color(
            bg_btn.GetComponent<Image>().color.r,
            bg_btn.GetComponent<Image>().color.g,
            bg_btn.GetComponent<Image>().color.b,0), 0.3f);
        go_RankList.transform.DOScale(Vector3.zero, 0.3f).OnComplete(()=> {
            gameObject.SetActive(false);
        });
    }
}
